ARG baseImage=node:15.14-buster-slim

# Base image release stage
FROM ${baseImage} AS base
WORKDIR /base
COPY package.json ./
COPY yarn.lock ./
RUN yarn install
COPY . .

# Production build stage
FROM base AS build
ENV NODE_ENV=production
WORKDIR /build
COPY --from=base /base ./
RUN yarn build:api

# Production release stage, start normal server by default
FROM ${baseImage} AS production
ENV NODE_ENV=production
WORKDIR /app
COPY --from=build /build/package.json ./
COPY --from=build /build/.next ./.next
COPY --from=build /build/public ./public
COPY --from=build /build/dist ./dist
COPY --from=build /build/next.config.js ./
RUN yarn add next

EXPOSE 3000
CMD yarn start